package com.demo1222.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;

@WebServlet("/demo1222/login.do")
public class InternationalServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String address = req.getParameter("Accept-Language");
        String str=address.split("\\,")[0];
        String language=str.split("\\-")[0];
        String country=str.split("\\-")[1];
        ResourceBundle res = ResourceBundle.getBundle("res", new Locale(language, country));
        String username = res.getString("msg.username");
        String password = res.getString("msg.password");
        req.setAttribute("username",username);
        req.setAttribute("password",password);
        req.getRequestDispatcher("/demo1222/1.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
